package com.powernode.rules.controller;

import com.powernode.common.result.Result;
import com.powernode.model.form.rules.RewardRuleRequestForm;
import com.powernode.model.vo.rules.RewardRuleResponseVo;
import com.powernode.rules.service.RewardRuleService;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 奖励规则控制器
 * 处理订单奖励相关的HTTP请求，提供奖励计算等功能接口
 */
@Slf4j
@RestController
@RequestMapping("/rules/reward")
@SuppressWarnings({"unchecked", "rawtypes"})
public class RewardRuleController {
    @Resource
    private RewardRuleService rewardRuleService;// 奖励规则服务，用于执行业务逻辑

    /**
     * 计算订单奖励费用接口
     * 根据请求参数计算符合条件的订单奖励金额
     *
     * @param rewardRuleRequestForm 请求体参数，包含计算奖励所需的信息（如订单数量等）
     * @return 响应结果，包含计算得到的奖励金额信息
     */
    @Operation(summary = "计算订单奖励费用")
    @PostMapping("/calculateOrderRewardFee")
    public Result<RewardRuleResponseVo> calculateOrderRewardFee(@RequestBody RewardRuleRequestForm rewardRuleRequestForm) {
        return Result.ok(rewardRuleService.calculateOrderRewardFee(rewardRuleRequestForm));
    }
}

